    var actualExpandedNode = "";
    var bound = "";
    var locationOfMouse = "";

    var secs;
    var timerID = null;
    var timerRunning = false;
    var delay = 500;

    //------Beginig of classes------
    function MenuNode(title, depth, url, hasChildren, parentId, childClientId)
    {
        this.title = title;
        this.depth = depth;
        this.url = url;
        this.hasChildren = hasChildren;
        this.parentId = parentId;
        this.childClientId = childClientId;
    }
    
    function Ids(id, clientId)
    {
        this.id = id;
        this.clientId = clientId;
    }
    //------End od classes------    


    //------Begining of sizeing------
	function resizeDiv(divId, percentage, width, height)
	{
		if(percentage <= 100)
		{
    		var div = document.getElementById(divId);
    		var img = document.getElementById(div.childNodes[0].id);
		    var table = document.getElementById(div.childNodes[1].id);
			div.style.width = Math.round((width / 100) * percentage) + "px";
			img.style.width = Math.round((width / 100) * percentage) + "px";
			div.style.height = Math.round((height / 100) * percentage) + "px";
			img.style.height = Math.round((height / 100) * percentage) + "px";
			setTimeout("resizeDiv('" + divId + "'," + (percentage + 10) + "," + width + "," + height + ")", 15);
		}
	}
	
	function decreaseDiv(divId, percentage, width, height)
	{
	    if(percentage >= 0)
	    {
	        var div = document.getElementById(divId);
    		var img = document.getElementById(div.childNodes[0].id);
		    var table = document.getElementById(div.childNodes[1].id);
			div.style.width = Math.round((width / 100) * percentage) + "px";
			img.style.width = Math.round((width / 100) * percentage) + "px";
			div.style.height = Math.round((height / 100) * percentage) + "px";
			img.style.height = Math.round((height / 100) * percentage) + "px";
			setTimeout("decreaseDiv('" + divId + "'," + (percentage - 10) + "," + width + "," + height + ")", 15);
	    }
	}	
	//------End of sizeing------
	
	
	//------Begining of design------
    function mouseOver(obj, title)
    {
        locationOfMouse = title;
        obj.style.backgroundColor = "#d9edff";
    }
    
    function mouseLeave(obj, title)
    {
        locationOfMouse = "";
        obj.style.backgroundColor = "";
        InitializeTimer();
    }
    //------End of design-----


    //------Begining of auto hide------
    function InitializeTimer()
    {
        secs = 2;
        StopTheClock();
        StartTheTimer();
    }

    function StopTheClock()
    {
        if(timerRunning)
	    {
            clearTimeout(timerID);
	    }
        timerRunning = false;
    }

    function StartTheTimer()
    {
        if (secs==0)
        {
            StopTheClock();
            for(var i = 0; i < menuNodes.length; i++)
	        {
	            if(menuNodes[i].title == actualExpandedNode && (menuNodes[i].title != locationOfMouse))
	            {
	                if(bound == "")
	                {
	                    hideDivRecursively(document.getElementById(menuNodes[i].childClientId));
	                    actualExpandedNode = "";
	                }
	                else if(bound != menuNodes[i].childClientId)
	                {
	                    //document.getElementById(menuNodes[i].childClientId).style.display = "none";
	                    var tempDiv = document.getElementById(menuNodes[i].childClientId);
	                    var table = tempDiv.childNodes[1];
	                    decreaseDiv(menuNodes[i].childClientId, 90, table.offsetWidth, table.offsetHeight);
	                    for(var j = 0; j < menuNodes.length; j++)
	                    {
	                        if(menuNodes[j].title == menuNodes[i].parentId)
	                        {
	                            var parent = menuNodes[j].childClientId;
	                            var parentParent = menuNodes[j].parentId;
	                            actualExpandedNode = menuNodes[j].title;
	                            while(parent != bound && actualExpandedNode != locationOfMouse)
	                            {
	                                //document.getElementById(parent).style.display = "none";
	                                tempDiv = document.getElementById(parent);
	                                table = tempDiv.childNodes[1];
	                                decreaseDiv(parent, 90, table.offsetWidth, table.offsetHeight);
	                                for(i = 0; i < menuNodes.length; i++)
	                                {
	                                    if(menuNodes[i].title == parentParent)
	                                    {
	                                        parent = menuNodes[i].childClientId;
	                                        parentParent = menuNodes[i].parentId;
	                                        actualExpandedNode = menuNodes[i].title;
	                                        break;
	                                    } 
	                                }
	                            }
	                            break;
	                        }
	                    }
	                }
	                break;
	            }
	        }
        }
        else
        {
            secs = Number(secs) - 1;
            timerRunning = true;
            timerID = self.setTimeout("StartTheTimer()", delay);
        }
    }
    
    function enterToTheDiv(obj)
    {
        bound = obj.id;        
    }
    
	function hideDiv(obj)
	{	
        bound = "";
        InitializeTimer();	    	
	}
        
    function enterToTheDivFF(e, obj)
    {    
        e = e || window.event;
        
	    if(!e)
	    {
	        return;
	    }

	    if(navigator.appName == "Microsoft Internet Explorer")
	    {
		    e.cancelBubble = true;
            return;
	    }
	    
	    if (obj.nodeName != 'DIV')
	    {
	        return;
	    }
	    
	    e.stopPropagation();
	    var reltg = e.relatedTarget;
	    
	    while ((reltg != obj) && (reltg.nodeName != 'BODY'))
	    {
		    reltg = reltg.parentNode
		}
		
	    if (reltg == obj)
	    { 
	        return;
	    }
	    bound = obj.id;    
    }
    
    function hideDivForFF(e, obj)
    {        
        e = e || window.event;
        
	    if(!e)
	    {
	        return;
	    }

	    if(navigator.appName == "Microsoft Internet Explorer")
	    {
		    e.cancelBubble = true;
            return;
	    }
	    
	    if (obj.nodeName != 'DIV')
	    {
	        return;
	    }
	    
	    e.stopPropagation();
	    var reltg = e.relatedTarget;
	    
	    while ((reltg != obj) && (reltg != null))
	    {
		    reltg= reltg.parentNode
		}
		
	    if (reltg == obj)
	    { 
	        return;
	    }
	    bound = "";
        InitializeTimer();	    	
	}
    //------Enf of auto hide------
    
    
    function isParent(which, whose)
	{
	    if(whose.parentId == which)
	    {
	        return true;
	    }
	    else if(whose.parentId != "");
	    {
	        for(i = 0; i < menuNodes.length; i++)
	        {
	            if(whose.parentId == menuNodes[i].title)
	            {
	                return isParent(which, menuNodes[i]);
	            }
	        }
	    }
	    return false;
	}
	
	function hideDivRecursively(obj)
	{
	    actualExpandedNode = "";	    
        for(var i = 0; i < menuNodes.length; i++)
        {
            if(menuNodes[i].childClientId == obj.id)
            {
                //obj.style.display = "none";
                var table = obj.childNodes[1];
                decreaseDiv(obj.id, 90, table.offsetWidth, table.offsetHeight);
                for(var k = 0; k < menuNodes.length; k++)
                {
                    if(menuNodes[k].title == menuNodes[i].parentId)
                    {
                        var parent = document.getElementById(menuNodes[k].childClientId);
                    }
                }
                if(parent != null)
                {
                    hideDivRecursively(parent);
                }
                break;
            }
        }
	}
		                   
	function setLyrOfMenu(obj, id)
	{
		InitializeTimer();
		
		if(actualExpandedNode == id)
		{
		    return;
		}
		
        if(actualExpandedNode != "")
        {
            for(var i = 0; i < menuNodes.length; i++)
            {
                if(actualExpandedNode == menuNodes[i].title)
                {
                    hideDivRecursively(document.getElementById(menuNodes[i].childClientId));
                    break;
                }
            }
        }		
		var coors = findPos(obj);
		var x;
		for(var i = 0; i < menuNodes.length; i++)
		{
		    if(menuNodes[i].title == id)
		    {
		        x = document.getElementById(menuNodes[i].childClientId);
		        break;
		    }
		}
		actualExpandedNode = id;
		x.style.top = coors[1] + 'px';
		x.style.left = coors[0] + 'px';
		x.style.display = "";
		var table = x.childNodes[1];
		resizeDiv(x.id, 10, table.offsetWidth, table.offsetHeight);
	}
	
	function setLyrOfSubMenu(obj, id)
	{
	    InitializeTimer();
	    
		if(actualExpandedNode == id)
		{
		    return;
		}
		
		var coors = findPosForSubMenu(obj);
	    
	    for(var i = 0; i < menuNodes.length; i++)
	    {
	        if(menuNodes[i].title == actualExpandedNode)
	        {
	            for(var j = 0; j < menuNodes.length; j++)
	            {
	                if(menuNodes[j].title == id && menuNodes[i].depth >= menuNodes[j].depth)
	                {
                        //document.getElementById(menuNodes[i].childClientId).style.display = "none";
                        var tempDiv = document.getElementById(menuNodes[i].childClientId);
                        var table = tempDiv.childNodes[1];
                        decreaseDiv(menuNodes[i].childClientId, 90, table.offsetWidth, table.offsetHeight);
                        var parent = menuNodes[i].parentId;
                        while(parent != menuNodes[j].parentId)
                        {
                            for(var k = 0; k < menuNodes.length; k++)
                            {
                                if(menuNodes[k].title == parent)
                                {
                                    //document.getElementById(menuNodes[k].childClientId).style.display = "none";
                                    tempDiv = document.getElementById(menuNodes[k].childClientId);
                                    table = tempDiv.childNodes[1];
                                    decreaseDiv(menuNodes[k].childClientId, 90, table.offsetWidth, table.offsetHeight);
                                    parent = menuNodes[k].parentId;
                                    break;
                                }                            
                            }
                        }
                        break;
	                }
	            }
	        }
	    }
			    		
		var x;		
		for(var i = 0; i < menuNodes.length; i++)
		{
		    if(menuNodes[i].title == id)
		    {
		        x = document.getElementById(menuNodes[i].childClientId);
		    }
		}
		actualExpandedNode = id;
		x.style.top = coors[1] + 'px';
		x.style.left = coors[0] + 'px';
		x.style.display = "";
		var table = x.childNodes[1];
		resizeDiv(x.id, 10, table.offsetWidth, table.offsetHeight);		
	}
	
	function findPosForSubMenu(obj)
	{
	    var curright = curtop = 0;
		if (obj.offsetParent)
		{
			curright = obj.offsetLeft + obj.offsetParent.offsetWidth;
			curtop = obj.offsetTop;
			while (obj = obj.offsetParent)
			{
				curright += obj.offsetLeft;
				curtop += obj.offsetTop;
			}
		}
		return [curright,curtop];	    
	}

	function findPos(obj)
	{
		var curleft = curbottom = 0;
		if (obj.offsetParent)
		{
			curleft = obj.offsetLeft;
			curbottom = obj.offsetTop + obj.offsetHeight;
			while (obj = obj.offsetParent)
			{
				curleft += obj.offsetLeft;
				curbottom += obj.offsetTop;
			}
		}
		return [curleft,curbottom];
	}
	
	function tdClick(e, obj, url)
	{
	    if (!e) var e = window.event;
        if (e.target)
        {
            if(obj == e.target)
            {
                beforeSubmit();
                window.location = url;
            }
            return;
        }
	    else if (e.srcElement)
	    {
	        if(obj == e.srcElement)
	        {
                beforeSubmit();
                window.location = url;
	        }
	        return;
	    }
	}
